<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML中的全局变量</title>
</head>

<body>
    <p>在 HTML 中, 所有全局变量都会成为 window 变量。</p>
    <p id="demo"></p>
    <script>
        myFunction()
        document.getElementById("demo").innerHTML =
            "我可以显示 " + window.carName;
        function myFunction() {
            carName = "Volvo";
        }
    </script>
</body>

</html>